#include "glutproject.h"
#include "extension/colors.h"
#include <GL/gl.h>
#include <GL/glut.h>
#include "point.h"
#include "bmath.h"
#include <iostream>
#include <iomanip>

using namespace bend2d;
using namespace std;

class myGlutProject : public GlutProject
{
    private:
        bool m_Run;
    public:
        myGlutProject()
        {
            m_Run = true;
        }

        void DrawSquare(int x, int y)
        {
            glBegin(GL_QUADS);
            glVertex2d(x - 10, y - 10);
            glVertex2d(x + 10, y - 10);
            glVertex2d(x + 10, y + 10);
            glVertex2d(x - 10, y + 10);
            glEnd();
        }

        void CustomRenderFunction()
        {
            glColor3f(0, 0, 1);
            DrawSquare(160, 120);

            static double angle = 0;
            static double radius = 100;

            Point redPoint(radius, Angle(angle));
            glColor3f(1, 0, 0);
            DrawSquare(redPoint.GetX() + 160, redPoint.GetY() + 120);

            if(m_Run)
                angle += 0.1;
        }

        void CustomIdleFunction()
        {
            RenderFunction();
        }

        void CustomMouseFunction(int button, int state, int x, int y)
        {
            if(state == GLUT_UP)
                m_Run = !m_Run;
        }

        void ClearFunction()
        {
            glClearColor(1, 1, 1, 1);
            glClear(GL_COLOR_BUFFER_BIT);
        }

        void GetWindowSize(int& width, int& height)
        {
            width = 320;
            height = 240;
        }

};

int main(int argc, char* argv[])
{
    myGlutProject project;
    project.Init(argc, argv);
    project.MainLoop();
    return 0;
}
